package com.campus.backend.controller;

import com.campus.backend.bean.feedback.FeedbackHandleBean;
import com.campus.backend.bean.feedback.FeedbackQueryParam;
import com.campus.backend.service.FeedbackService;
import com.campus.backend.vo.feedback.FeedbackVo;
import com.campus.common.bean.common.Pagination;
import com.campus.common.bean.common.Resp;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 意见反馈表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-05-21
 */
@Api(tags = "意见反馈管理")
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    /**
     * 分页查询反馈列表
     *
     * @param param 查询参数
     * @return 分页结果
     */
    @ApiOperation("分页查询反馈列表")
    @GetMapping("/page")
    public Resp<Pagination<FeedbackVo>> page(@Validated FeedbackQueryParam param) {
        PageInfo<FeedbackVo> pageInfo = feedbackService.getFeedbackListPage(param);
        return Resp.successPageable(pageInfo);
    }

    /**
     * 获取反馈详情
     *
     * @param feedbackId 反馈ID
     * @return 反馈详情
     */
    @ApiOperation("获取反馈详情")
    @GetMapping("/{feedbackId}")
    public Resp<FeedbackVo> detail(@PathVariable Integer feedbackId) {
        FeedbackVo feedbackVo = feedbackService.getFeedbackById(feedbackId);
        return Resp.success(feedbackVo);
    }

    /**
     * 处理反馈
     *
     * @param handleBean 处理参数
     * @return 处理结果
     */
    @ApiOperation("处理反馈")
    @PutMapping("/handle")
    public Resp<String> handle(@RequestBody @Validated FeedbackHandleBean handleBean) {
        feedbackService.handleFeedback(handleBean);
        return Resp.success();
    }

    /**
     * 删除反馈
     *
     * @param feedbackId 反馈ID
     * @return 删除结果
     */
    @ApiOperation("删除反馈")
    @DeleteMapping("/{feedbackId}")
    public Resp<String> delete(@PathVariable Integer feedbackId) {
        feedbackService.deleteFeedback(feedbackId);
        return Resp.success();
    }
}
